package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.sbj.dto.req.AddressReq;
import com.sbj.dto.res.AddressRes;
import com.sbj.service.IAddressService;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/11 20:54
 */
@RequestMapping(value = "/address")
@RestController
@AllArgsConstructor
public class MemberAddressController {

   private final IAddressService addressService;

    /**
     *  增加收货地址
     * @return
     */
    @PostMapping(value = "/addAddress")
    public Result<String> addAddress(@RequestBody AddressReq addressReq){
        addressService.addAddress(addressReq);
        return Result.successResult();
    }

    /**
     * 收货地址列表
     * @return
     */
   @GetMapping(value = "/lists")
   public Result<List<AddressRes>> lists(){
       return Result.successResult(addressService.lists());
   }

    /**
     * 根据id查询
     * @param addressId
     * @return
     */
   @GetMapping(value = "/findByAddressId/{addressId}")
   public Result<AddressRes> findByAddressId(@PathVariable Integer addressId){
       return Result.successResult(Convert.convert(AddressRes.class,addressService.getById(addressId)));
   }

    /**
     * 删除地址
     * @param addressId
     * @return
     */
   @GetMapping(value = "/removeAddress")
   public Result<String> removeAddress(@PathVariable Integer addressId){
       addressService.removeById(addressId);
       return Result.successResult();
   }

    /**
     * 修改地址
     * @param addressReq
     * @return
     */
   @PostMapping(value = "/modifyAddress")
   public Result<String> modifyAddress(@RequestBody AddressReq addressReq){
       addressService.addAddress(addressReq);
       return Result.successResult();
   }
}
